<?php

namespace app\index\model;

use  think\Db;

class ShipModel
{
    static public function getList($param, $titles = null, $function = null){
        $db = Db::table('ship_plan');
        !empty($param['code'])&&$db->where('code', 'in',explodeStr($param['code']));
        !empty($param['shop_id_rec'])&&$db->where('shop_id_rec', 'in',explodeStr($param['shop_id_rec']));
        !empty($param['ship_time_early'])&&$db->where('ship_time_early', $param['ship_time_early']);
        !empty($param['ship_time_late'])&&$db->where('ship_time_late', $param['ship_time_late']);
        $db->order('id','desc');
        return \app\common\service\ToolService::downOrReturn($db, $param, $titles, $function);
    }
    static public function getSKuNum($planIds){
        return DB::table('ship_plan_detail')
            ->where('ship_plan_id','in',$planIds)
            ->group('ship_plan_id')
            ->column("count(sku) as sku_num","ship_plan_id");
    }
    static public function logistics($param, $titles = null, $function = null){
        $db = Db::table('ship_plan_logistics')->alias("a")
            ->field('a.*,b.quantity')
            ->join('ship_plan_receive b','a.code=b.code and a.box_number=b.case_number','left')
            ->where("a.code",$param['code']);
        return \app\common\service\ToolService::downOrReturn($db, $param, $titles, $function);
    }
    static public function receiveQuantity($caseNumber){
        return Db::table('ship_plan_receive')
            ->where("case_number",'in',$caseNumber)
            ->group('code')
            ->value('sum(quantity) as quantity',0);
    }
}